		<script src="../scriptaculous/lib/prototype.js" type="text/javascript"></script>
        <script type="text/javascript" src="../scripts.js" language="javascript"></script>


<?php
	error_reporting(0);
	$token='251024371578319|8633ce846ef41a043a8e51de.1-1037952268|1bjRFzbSci6231l14UABxoGiC9Q';
 
  include ('../Connections/conn.php');	
  require_once 'class.xhttp.php';
	
	$data = array();
   $data['get'] = array(
      'access_token'  => $token,
      'fields' => 'id,name,accounts'
      );
	  
	  
   $response = xhttp::fetch('https://graph.facebook.com/me', $data);
   $friends = xhttp::fetch('https://graph.facebook.com/me/friends?access_token='.$token);
   
    $user= json_decode($response['body'], true);
    //print_r($user);
    //echo $user['name'].' '.$user['id'];
    
    $link=mysql_connect("localhost","root","");
		mysql_select_db("totus");
	$query="SELECT MAX(date) FROM posts WHERE `to`='".$user['id']."'";
	//echo $query;
	$consulta=mysql_query($query,$link);
	$row=mysql_fetch_array($consulta);
	//echo $row['MAX(date)'];
	
	$pensando = xhttp::fetch('https://graph.facebook.com/me/feed?access_token='.$token);
	//print_r($pensando);
	$muro=json_decode($pensando['body'],true);
	$i=0;
	foreach ($muro['data'] as $uno)
	{	
		
		$partida1=explode("T",$uno['created_time']);
		$partida2=explode("+",$partida1[1]);
		$junto=$partida1[0]." ".$partida2[0];
		$fecha_post=strtotime($junto);
		$fecha_max= strtotime($row['MAX(date)']);
		
		if($fecha_post>$fecha_max)
		{
			$i++;
			echo $uno['from']['name'].": ". $uno['message'];
			echo "<br>";
			 
	$query2="SELECT id_usuarios,Departamento_id_departamento as depto FROM usuarios WHERE nombre='". $uno['from']['name']."'";
	$consulta2=mysql_query($query2,$conexion);
			if(mysql_num_rows($consulta2)>0)
			{
				$row2=mysql_fetch_array($consulta2);
				?>
				<script>ventanita('ticket/ver_cate2.php?usuario=<?php echo $row2['id_usuarios']?>&depto=<?php echo $row2['depto']?>&descrip=<?php echo $uno['message']?>&facebook=1&idcoment=<?php echo $uno['id'];?>&from=<?php echo $uno['from']['id'];?>&mio=<?php echo $user['id']?>&message=<?php echo $uno['message'];?>&fecha=<?php echo $junto;?>','Seleccionar Asunto');</script>
				<?php
			}
			else
			{?>
			 <form id="contesta_<?php echo $i;?>" name="contesta_<?php echo $i;?>" method='post' action="javascript: forms(document.getElementById('contesta_<?php echo $i;?>'),'facebook/insertaPost.php','respuesta_<?php echo $i;?>')">
             <div id='respuesta_<?php echo $i;?>'>
              <label class="desc">Mensaje</label>
              <br/>
              <textarea name="comentario" id="comentario" style="width:200px; height:100px;" class="required" value="" title="ingrese la descripcion"></textarea>
              <input type="hidden" name="token" id='token' value='<?php echo $token;?>'>
				<input type="hidden" name="idcomen" id='idcomen' value='<?php echo $uno['id'];?>'>
		<input type="hidden" name="id" id='id' value='<?php echo $uno['from']['id'];?>'>
		<input type="hidden" name="mio" id="mio" value='<?php echo $user['id']?>'>
                   <div id="barra">
                    <input type="submit" value="Enviar">   
                 </div>
              </div>
                </form>
		<?php	
			}
		
		}
		
	}
	
	
	
	
?>
